`
https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var findMin = function (nums) {
  const n = nums.length
  if (n === 1 || nums[0] < nums[n - 1]) return nums[0]

  let left = 0, right = n - 1
  const last = nums[n - 1]

  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (nums[mid] > last) {
      left = mid
    } else if (nums[mid] < last) {
      right = mid
    }
  }

  // left 会停在最大值的位置，right 会停在 left 的下一位，也就是最小值
  return nums[right]
};